<?php

namespace App\Model;

class Wx
{
    public static function wxhttpRequest($domain)
    {
        $url = 'https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxcheckurl?requrl=https%3A%2F%2F'.$domain.'&skey=%40crypt_51c9bf42_8ce2c88a62b61d65193c62bf9270c16b&deviceid=e451517101450314&pass_ticket=undefined&opcode=2&scene=1&username=@b68e1d3ba6c183cbc663de2d508fc72314b997960ef1daf5ddf963248ecb3c61';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //换网页版微信cookie
        //xzh
        // mick
        // $cookie = 'pgv_pvi=6203482112; pgv_pvid=2641401122; MM_WX_NOTIFY_STATE=1; MM_WX_SOUND_STATE=1; pgv_info=ssid=s2903265034; pgv_si=s6643979264; pac_uid=0_5cbd6703eb4b4; wxuin=719293304; webwxuvid=ddddfdaa53fa07ab6dc58c3793744cd997880b142569e0e575ca98212913e581a3e9979dd82f44e02bf59942376b8ba7; webwx_auth_ticket=CIsBEIaH69gDGoABEQu3xUf+6AbiQ7spEoDmQCUISjP9cCCgPORYPBVDCUw2BweUJSayBVqBRaNZF5csx2ztLJ2YnQx9Qiw9mH0EU9h4iHSgDM1daxou8lukGffB8VdsE8jTVjs5upaL6f6Vdx5WYodoLyraAF8fO+sChhbu52/xpVX4gF2AZLlcYZM=; wxpluginkey=1558913958; mm_lang=en; wxsid=6Mp0cu+MHNLCgqO3; wxloadtime=1558922244_expired; webwx_data_ticket=gSd5OAni5zFxC60Y6S5ITxqW; login_frequency=1; last_wxuin=719293304';
        // $user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0';
        // shangning1866
        $cookie = 'pgv_pvi=9165647872; RK=g46Zj8V5X7; pac_uid=0_5ce5f7dcb7886; ptcz=e9b4c862bef31bc8fa9cf9346cf5c9d498ccf80d000ef495d31b38ad6fbeaf18; pgv_pvid=9394787265; webwxuvid=92b40f55664a2bd84c34c067ab99720226bc423590a1eebc616782baedf28c0961f569624c42335bc8c4606af5ff6676; webwx_auth_ticket=CIsBEM+g0OwCGoABNFtJhc5hjBTfORm+oViTxe94no+UfEhb307eezJFrhqh5lhVvZViFKT4B+nlAUCvi66x5uFqrJen2L0CSFbIU9k202z+FGYtCND4JgDgwq8P2uwmlnmMMjejKtOnR7dZxy5S+9Oee9nDFbs9jZ8oJ21aPMnXPlv9j0fZINVnMV0=; UM_distinctid=16b2abf002b0-0e62b0066ee43d-76212462-140000-16b2abf002c5d; mm_lang=zh_CN; MM_WX_NOTIFY_STATE=1; MM_WX_SOUND_STATE=1; CNZZDATA1272960370=1930001282-1559789583-https%253A%252F%252Fwx.qq.com%252F%7C1560038076; wxpluginkey=1560037997; wxuin=548327195; wxsid=J/S3qjnL4D5DRsp6; webwx_data_ticket=gSfpS+OMuYxAFcJ7VxPwr8p3';
        $user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36';
        curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        $output = curl_exec($ch);
        // $request_header = curl_getinfo($ch,CURLINFO_HEADER_OUT);
        curl_close($ch);
        // dump($request_header);
        $output_arr = json_decode($output, true);
        if (strpos($output_arr['FullURL'], 'weixin110.qq.com')) {
            // file_put_contents('./wxurls.log', '检测域名被封记录:'.date('Y-m-d : h:i:sa',time()).'检查url:'.$domain."\n", FILE_APPEND);
            return ['status' => 2, 'errmsg' => '系统check1检测域名被封', 'url' => $domain];
        } elseif (empty($output_arr['FullURL']) || $output_arr == null) {
            return ['status' => 3, 'errmsg' => '系统check1检测失效,请联系管理员', 'url' => $domain];
        } else {
            // 写入本地日志 每小时创建一个文件
            file_put_contents('./logs/requestMsg'.date('YmdH',time()).'.log', '检查系统日志记录:'.date('Y-m-d : h:i:sa',time()).'检查url:'.$domain."\n", FILE_APPEND);
            // return ['status' => 1, 'errmsg' => '测试系统发送信息', 'url' => $domain];
        }
    }
}
